package io.geekidea.springbootplus.system.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.system.entity.TaskTemp;
import io.geekidea.springbootplus.system.service.TaskTempService;
import lombok.extern.slf4j.Slf4j;
import io.geekidea.springbootplus.system.param.TaskTempPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.system.vo.TaskTempQueryVo;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.common.param.IdParam;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *  控制器
 *
 * @author miko
 * @since 2020-12-27
 */
@Slf4j
@RestController
@RequestMapping("/taskTemp")
@Module("system")
@Api(value = "API", tags = {""})
public class TaskTempController extends BaseController {

    @Autowired
    private TaskTempService taskTempService;

    /**
     * 添加
     */
    @PostMapping("/add")
    @RequiresPermissions("task:temp:add")
    @OperationLog(name = "添加", type = OperationLogType.ADD)
    @ApiOperation(value = "添加", response = ApiResult.class)
    public ApiResult<Boolean> addTaskTemp(@Validated(Add.class) @RequestBody TaskTemp taskTemp) throws Exception {
        boolean flag = taskTempService.saveTaskTemp(taskTemp);
        return ApiResult.result(flag);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("task:temp:update")
    @OperationLog(name = "修改", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改", response = ApiResult.class)
    public ApiResult<Boolean> updateTaskTemp(@Validated(Update.class) @RequestBody TaskTemp taskTemp) throws Exception {
        boolean flag = taskTempService.updateTaskTemp(taskTemp);
        return ApiResult.result(flag);
    }

    /**
     * 删除
     */
    @PostMapping("/delete/{id}")
    @RequiresPermissions("task:temp:delete")
    @OperationLog(name = "删除", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除", response = ApiResult.class)
    public ApiResult<Boolean> deleteTaskTemp(@PathVariable("id") Long id) throws Exception {
        boolean flag = taskTempService.deleteTaskTemp(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取详情
     */
    @GetMapping("/info/{id}")
    @RequiresPermissions("task:temp:info")
    @OperationLog(name = "详情", type = OperationLogType.INFO)
    @ApiOperation(value = "详情", response = TaskTempQueryVo.class)
    public ApiResult<TaskTempQueryVo> getTaskTemp(@PathVariable("id") Long id) throws Exception {
        TaskTempQueryVo taskTempQueryVo = taskTempService.getTaskTempById(id);
        return ApiResult.ok(taskTempQueryVo);
    }

    /**
     * 分页列表
     */
    @PostMapping("/getPageList")
    @RequiresPermissions("task:temp:page")
    @OperationLog(name = "分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "分页列表", response = TaskTempQueryVo.class)
    public ApiResult<Paging<TaskTempQueryVo>> getTaskTempPageList(@Validated @RequestBody TaskTempPageParam taskTempPageParam) throws Exception {
        Paging<TaskTempQueryVo> paging = taskTempService.getTaskTempPageList(taskTempPageParam);
        return ApiResult.ok(paging);
    }


/**
 * 分页列表
 */
@PostMapping("/getAll")
    @RequiresPermissions("task:temp:page")
    @OperationLog(name = "所有列表", type = OperationLogType.PAGE)
@ApiOperation(value = "所有列表", response = TaskTemp.class)
public ApiResult<List<TaskTemp>> getAll() throws Exception {
        LambdaQueryWrapper<TaskTemp> wrapper = new LambdaQueryWrapper<>();
        List<TaskTemp> list = taskTempService.getAllList(wrapper);
        return ApiResult.ok(list);
        }

}
